package com.stray.crawl.expr.psr;

import java.util.List;

import com.stray.crawl.expr.EventData;
import com.stray.crawl.expr.Express;

public class SublistParser extends Express {

	@Override
	protected Object doParse(EventData event) {
		Object obj = event.getObject();
		List<?> list = (List<?>) obj;
		int[] ranges = event.toIntArrayArgument();

		int fmIdx = ranges[0];
		int toIdx = list.size() - ranges[1];

		boolean fmCrt = fmIdx > 0 && fmIdx < list.size() - 1;
		boolean toCrt = toIdx > fmIdx && toIdx < list.size() - 1;

		if (fmCrt && toCrt) {
			obj = list.subList(fmIdx, toIdx);
		}

		return obj;
	}

}